home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Celestin Apprentice 4
/
Apprentice-Release4.iso
/
Source Code
/
Libraries
/
Graphic Elements 3
/
GEDemo
/
Walk.c
< prev
next >
Wrap
Text File
|
1995-08-25
|
4KB
|
124 lines
/*
Walk.c
Animated walking figure on balcony
Copyright 1993 by Al Evans. All rights reserved.
11/8/93
*/
#include "Walk.h"
#include "Motion.h"
#include "SFXCtrlr.h"
#include "SFXProcs.h"
#include "GESound.h"
pascal void DisposeWalker(GEWorldPtr world, GrafElPtr walker)
{
if (walker->drawData)
DisposPtr(walker->drawData);
if (walker->changeData)
DisposPtr(walker->changeData);
}
Boolean LoadBalconyScene(GEWorldPtr world)
{
GrafElPtr thisElement;
Rect balconyBox; //Walking figure positioned relative to balcony
short elemHeight;
MParamPtr walkMotion;
//Get railing of balcony
thisElement = NewBasicPICT(world, balconyID, balconyPlane, rBalconyPic,
transparent, balconyLeft, balconyTop);
if (thisElement == nil) return false;
balconyBox = thisElement->animationRect;
//Get walking figure
thisElement = NewAnimatedGraphic(world, walkID, walkPlane, rAnimWalk,
transparent, 0, 0, 10);
if (thisElement == nil) return false;
//Draw walker masked
thisElement->drawData = MakeMask(&((GrafPtr) thisElement->graphWorld)->portBits, 0);
thisElement->copyMode = srcCopy;
//Be sure to dispose mask & motion
SetCleanupProc(world, walkID, DisposeWalker);
//Position figure relative to balcony
elemHeight = thisElement->graphRect.bottom - thisElement->graphRect.top;
PtrMoveElementTo(world, thisElement, balconyBox.left + ScaleToWorld(world, 20),
balconyBox.bottom - ScaleToWorld(world, 10) - elemHeight, false);
//Initialize motion fields -- never collide with top or bottom
walkMotion = (MParamPtr) NewPtrClear(sizeof(MotionParams));
InitMotion(walkMotion, 100, 100);
walkMotion->currMotion.h = 6;
walkMotion->limitRect.top = 0;
walkMotion->limitRect.left = balconyBox.left + ScaleToWorld(world, 5);
walkMotion->limitRect.bottom = 1000;
walkMotion->limitRect.right = balconyBox.right - ScaleToWorld(world, 16);
//Initialize figure's walking action
SetAutoChange(world, walkID, DoWalker, (Ptr) walkMotion, 133);
//And set animation style to "loop"
((SeqGraphicPtr) thisElement)->seq = loop;
//Load speed control slider
thisElement = NewSliderSensor(world, sliderID, sliderPlane, rSliderBkg,
sliderLeft, sliderTop, hSlideSensor, rSliderCtrl);
if (thisElement == nil) return false;
SetSliderPercent(world, sliderID, 50);
SetSensorAction(world, sliderID, AdjustSpeed);
(void) DoGESFX(world, 'SFX1', thisElement, SFXHWipe, 30, 3000, 40, true, true);
return true;
}
pascal void DoWalker(GEWorldPtr world, GrafElPtr walker)
{
MParamPtr motion;
GEDirection collisionDir;
motion = (MParamPtr) walker->changeData;
collisionDir = CheckLimits(&walker->animationRect, &motion->limitRect);
if ((collisionDir == left) || (collisionDir == right)) {
motion->currMotion.h = -motion->currMotion.h;
SetMirroring(world, walker->objectID, (collisionDir == right), false);
}
MoveElement(world, walker->objectID, motion->currMotion.h, motion->currMotion.v);
BumpFrame(world, walker->objectID);
if (world->userData != nil) { // if we have a sound record
if ((((SeqGraphicPtr) walker)->currentFrame == 3) ||
(((SeqGraphicPtr) walker)->currentFrame == 8))
GEScheduleSound((GESoundPtr) world->userData, rWalkSnd, 1, 0);
}
}
pascal void AdjustSpeed(GEWorldPtr world, GrafElPtr ignore, short newSpeed)
{
GrafElPtr walker;
long newIntrvl;
walker = FindElementByID(world, walkID);
if (walker) {
newIntrvl = (newSpeed * 240) / 100;
if (newIntrvl > 0) {
newIntrvl = 240 - newIntrvl;
if (newIntrvl < 16)
newIntrvl = 16;
}
walker->changeIntrvl = newIntrvl;
}
}